<%@ page import="java.util.List" %>
<%@ page import="com.game.CartDAO" %>
<%@ page import="com.game.Game" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <title>购物车</title>
  <style>a{TEXT-DECORATION:none}</style>
</head>
<body>
<div style="text-align: center">

<h2>您的购物车</h2>
<%
  CartDAO cartDAO = new CartDAO();
  HttpSession ession = request.getSession();
  Integer userId = (Integer) ession.getAttribute("userId");
  if (userId == null) {
    response.sendRedirect("login.jsp");
  } else {
    List<Game> cartItems = cartDAO.getCartItems(userId);
%>
  <div style="text-align: center">
<table border="1">

  <tr>
    <th>游戏名称</th>
    <th>单价</th>
    <th>数量</th>
    <th>操作</th>
  </tr>
  <% for (Game game : cartItems) { %>
  <tr>
    <td><%= game.getName() %></td>
    <td>￥<%= game.getPrice() %></td>
    <td>
      <form action="cart" method="post">
        <input type="hidden" name="gameId" value="<%= game.getId() %>">
        <input type="number" name="quantity" value="1" min="1">
        <input type="hidden" name="action" value="update">
        <input type="submit" value="更新">
      </form>
    </td>
    <td>
      <form action="cart" method="post">
        <input type="hidden" name="gameId" value="<%= game.getId() %>">
        <input type="hidden" name="action" value="remove">
        <input type="submit" value="移除">
      </form>
    </td>
  </tr>
  <% } %>
</table></div>
<% } %>
</div>
</body>
</html>